package cn.cqnu.interceptor;

import cn.cqnu.exception.ParamsException;
import cn.cqnu.global.SystemReturnEnum;
import cn.cqnu.utils.JWTUtils;
import cn.hutool.core.util.StrUtil;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class JwtInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //    从请求头中尝试获取token
        String token = request.getHeader("token");
        //    调用工具类查看jwt是否合法
//        if (StrUtil.isBlank(token) || !JWTUtils.verify(token))
//            throw new ParamsException(SystemReturnEnum.NEED_LOGIN);

        //    合法放行, 非法则抛出异常,再由同一异常处理拦截

        return true;
    }

}
